home *** CD-ROM | disk | FTP | other *** search
- /*
- Filename Mystic Rose.c
- Copyright © 1994 David Hart. All rights reserved.
- Author David Hart
- Description Mystic Rose module for After Dark
-
- Version Date Comments
- 2.00 18/04/94 Original version for After Dark version 2.0
- */
-
- #include <QuickDraw.h>
- #include <Memory.h>
- #include <OSUtils.h>
- #include <math.h>
- #include "GraphicsModule_Types.h"
-
- /* Function prototypes */
- void Wait(int ticks);
-
- /* Color Table */
- long Colors[] = {
- /* blackColor, */
- whiteColor,
- redColor,
- greenColor,
- blueColor,
- cyanColor,
- magentaColor,
- yellowColor };
-
- /* Specific graphics module data structures */
- typedef struct MyStorage
- {
- int numPoints;
- int length;
- int point1;
- int point2;
- } MyStorage, *MyStoragePtr, **MyStorageHandle;
-
- /*
- DoInitialize is the first function called from After Dark.
- Memory for the structure is allocated and the variables are initialized.
- The allocated memory is assigned to "storage"
- and the function returns "noErr" if there are no problems.
- */
- OSErr DoInitialize(Handle *storage, RgnHandle blankRgn, GMParamBlockPtr params)
- {
- MyStorageHandle myStorage;
-
- /* allocate handle to my storage */
- myStorage = (MyStorageHandle)NewHandle(sizeof(MyStorage));
-
- if (!myStorage)
- return MemError();
-
- MoveHHi(myStorage);
- HLock(myStorage); /* Lock it down */
-
- *storage = (Handle)myStorage; /* Assign myStorage to passed handle */
-
- (**myStorage).numPoints = params->controlValues[0] / 3 + 4;
- (**myStorage).length = 1;
- (**myStorage).point1 = 0;
- (**myStorage).point2 = 1;
- HUnlock(myStorage);
- return noErr;
- }
-
- /*
- DoBlank is the next function called.
- It is used to simply blank the screen.
- */
- OSErr DoBlank(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params)
- {
- FillRgn(blankRgn, params->qdGlobalsCopy->qdBlack);
- return noErr;
- }
-
- /*
- DoDrawFrame does almost all of the work.
- */
- OSErr DoDrawFrame(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params)
- {
- OSErr err = noErr;
- MyStoragePtr myStorage; /* to hold dereferenced storage handle */
- int minSize;
- int maxSize;
- int x1, y1;
- int x2, y2;
- int radius;
- double theta;
-
- int width;
- int height;
- int size;
- int color;
- int monitor;
- int xmid;
- int ymid;
- Rect rect;
-
- /* Lock our storage down so we can dereference it once for faster access */
- MoveHHi(storage);
- HLock(storage);
- myStorage = (MyStoragePtr)*storage;
-
- /* Get params */
- minSize = params->controlValues[0] / 3 + 4;
- maxSize = params->controlValues[1] / 3 + 4;
-
- /* Color */
- switch (params->controlValues[3])
- {
- case 8: /* rainbow */
- color = myStorage->point1 % 7 + 1;
- break;
- case 9: /* cycle */
- color = myStorage->numPoints % 7 + 1;
- break;
- default:
- color = params->controlValues[3] - 1;
- break;
- }
-
- /* For each monitor */
- for (monitor = 0; monitor < params->monitors->monitorCount; monitor++)
- {
- rect = params->monitors->monitorList[monitor].bounds;
- xmid = (rect.left + rect.right) / 2;
- ymid = (rect.top + rect.bottom) / 2;
- width = rect.right - rect.left;
- height = rect.bottom - rect.top;
- size = width < height ? width : height;
- radius = size / 2;
-
- theta = 2 * 3.14159 / myStorage->numPoints;
-
- /* Calculate coords of point1 */
- x1 = cos(theta * myStorage->point1) * radius;
- y1 = sin(theta * myStorage->point1) * radius;
-
- /* Calculate coords of point2 */
- myStorage->point2 = myStorage->point1 + myStorage->length;
- x2 = cos(theta * myStorage->point2) * radius;
- y2 = sin(theta * myStorage->point2) * radius;
-
- /* Draw line from point1 to point2 */
- ForeColor(Colors[color]);
- MoveTo(x1 + xmid, y1 + ymid);
- LineTo(x2 + xmid, y2 + ymid);
- }
-
- /* Next point1 */
- myStorage->point1++;
- if (myStorage->point1 >= myStorage->numPoints)
- {
- /* All points done, reset and try longer line */
- myStorage->point1 = 0;
-
- /* Increase line length */
- myStorage->length++;
- if (myStorage->length >= myStorage->numPoints/2+1)
- {
- /* All lines done, reset and try more points */
- myStorage->length = 1;
-
- /* Increase number of points */
- myStorage->numPoints++;
- if (myStorage->numPoints > maxSize)
- {
- /* Max number of points done, reset to min */
- myStorage->numPoints = minSize;
- }
-
- /* Delay before blanking screen */
- Wait(120);
- ForeColor(blackColor);
- FillRgn(blankRgn, params->qdGlobalsCopy->qdBlack);
- }
- }
-
- HUnlock(storage);
- return noErr;
- }
-
- /*
- DoClose is called when the user quits the screen saver.
- The memory is deallocated and the function returns "MemError"
- which will tell After Dark if there was a problem
- */
- OSErr DoClose(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params)
- {
- MyStorageHandle myStorage = (MyStorageHandle)storage;
-
- /* Deallocate our storage */
- if (myStorage)
- {
- MoveHHi(myStorage);
- HLock(myStorage);
- DisposHandle(storage);
- }
-
- /* check for memory errors */
- return MemError();
- }
-
- /*
- DoSetUp is called if the user clicks on a button in the Control Panel.
- */
- OSErr DoSetUp(RgnHandle blankRgn, short message, GMParamBlockPtr params)
- {
- return noErr;
- }
-
- /*
- Wait delays ticks TickCount
- */
- void Wait(int ticks)
- {
- long tickCount = TickCount();
-
- while (TickCount() < tickCount + ticks);
- }
-